package cfar.ff.fun;

import cfar.ff.data.Assocs.Assoc2;
import cfar.ff.data.List;
import cfar.ff.interfaces.Sequence;
import java.util.Iterator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
//import static cfar.ff.fun.F2W.$$;
import static cfar.ff.fun.Curry.curry;

/**
 *
 * @author badi
 */
public class mappings {

//    public static final class Map<F,A,B> implements F3<Strategy<F,A,B>, F1<A, B>, Sequence<F, A>, Sequence<F, B>> {
//
//        public Sequence<F, B> f(Strategy<F, A, B> st, F1<A, B> f, Sequence<F, A> s) {
//            return st.f(f, s);
//        }
//    }
//
//    public static <F,A,B> F3<Strategy<F,A,B>, F1<A, B>, Sequence<F, A>, Sequence<F, B>> map() {
//        return new Map<F,A,B>();
//    }
//
//    public static abstract class Strategy<F, A, B> implements F2<F1<A, B>, Sequence<F, A>, Sequence<F, B>> {
//
//        protected F2<F1<A, B>, Sequence<F, A>, Assoc2<Sequence<F, B>, Iterator<A>>> first(){
//            return new F2<F1<A, B>, Sequence<F, A>, Assoc2<Sequence<F, B>, Iterator<A>>>() {
//
//                public Assoc2<Sequence<F, B>, Iterator<A>> f(F1<A, B> f, Sequence<F, A> s) {
//                    Iterator<A> i = s.iterator();
//                    A a = i.next();
//                    return new Assoc2<Sequence<F, B>, Iterator<A>>((Sequence<F, B>) s.pure(f.f(a)), i);
//                }
//            };
//        }
//
//        public abstract Sequence<F, B> f(F1<A, B> f, Sequence<F, A> s);
//
//    }
//
//    public static class Seq<F, A, B> extends Strategy<F, A, B> {
//
//        public Sequence<F, B> f(F1<A, B> f, Sequence<F, A> s) {
//            Assoc2<Sequence<F, B>, Iterator<A>> assoc = first().f(f, s);
//            Sequence<F, B> other = assoc.$1();
//            Iterator<A> as = assoc.$2();
//            while (as.hasNext()) {
//                other = other.concat((Sequence<F, B>) s.pure(f.f(as.next())));
//            }
//            return other;
//        }
//    }


//    public static class Par<F,A,B> extends Strategy<F,A,B> {
//
//        @Override
//        public Sequence<F, B> f(F1<A, B> f, Sequence<F, A> s) {
//            ExecutorService pool = Executors.newCachedThreadPool();
//            List<Future<B>> futures = new List();
//
//            Iterator<A> i = s.iterator();
//            while(i.hasNext())
//                futures.cons(pool.submit(curry(f, i.next())));
//
//            List<Sequence<F, F,B>> bs = new List<Sequence<F, B>>();
//            for(Future<B> fb : futures){
//                Sequence<F, F,B> sb = (Sequence<F, B>) s.pure(fb.get());
//            }
//
//        }
//    }

}
